package com.yb.nowcoder;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * 华为机试练习第8题
 */
public class Main8 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            Map<Integer, Integer> treeMap = new TreeMap<>();
            for (int i = 0; i < n; i++) {
                Integer key = in.nextInt();
                Integer value = in.nextInt();
                if (treeMap.containsKey(key)) {
                    treeMap.put(key, value + treeMap.get(key));
                } else {
                    treeMap.put(key, value);
                }
            }
            for (Integer key : treeMap.keySet()) {
                System.out.println(key + " " + treeMap.get(key));
            }
        }
    }
}
